<template>
  <div class="list">
    <van-nav-bar left-text="排行榜" left-arrow @click-left="onClickLeft" />

    <!-- 排行榜列表 -->
    <div class="ranking">
      <div
        class="listbox"
        v-for="(item, index) in topData"
        :key="index"
        @click="viewRanking(item.id)"
      >
        <div class="img">
          <van-image :src="item.coverImgUrl" lazy-load>
            <template v-slot:loading>
              <van-loading type="spinner" size="20" />
            </template>
          </van-image>
        </div>

        <div class="text">{{ item.name }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Rankinglist",

  data() {
    return {
      topData: [],
    };
  },

  created() {
    //获取榜单数据
    this.getToplist();
  },

  methods: {
    //返回
    onClickLeft() {
      this.$router.go(-1);
    },

    //获取榜单数据
    getToplist() {
      this.axios({
        method: "get",
        url: "/toplist",
      })
        .then((res) => {
          this.topData = res.data.list;
        })
        .catch((err) => {
          
        });
    },

    //查看排行榜页面
    viewRanking(id) {
      this.$router.push({ name: "Ranking", params: { id } });
    },
  },
};
</script>

<style lang="less" scoped>
//导航栏
/deep/.van-nav-bar .van-icon {
  color: #3e3e3e;
  font-weight: 600;
}

/deep/.van-nav-bar__text {
  color: #3e3e3e;
  font-weight: 600;
}

// 排行榜列表
.ranking {
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  margin-top: 10px;
}

.listbox {
  width: 30%;
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.img {
  width: 100%;
  height: 120px;
  border-radius: 10px;
}

.img {
  &/deep/ .van-image__img {
    width: 100%;
    height: 120px;
    border-radius: 10px;
  }
}

.text {
  width: 100%;
  padding-top: 4px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}
</style>